﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Configuration;

/// <summary>
/// Summary description for D_Change_Password
/// </summary>
namespace Bestlife.ERP.DataAccess
{
    public class D_Change_Password
    {
        public D_Change_Password()
        {
            //
            // TODO: Add constructor logic here
            //
        }
        #region Check Old Password
       
        public static String pass(string uname,string pass)
        {
            Bestlife.ERP.DataAccess.users user = new users();
            string uid = user.GetUserId(uname);
            

            string password =pass;
            SqlConnection conn_new = new SqlConnection();
            try
            {
                String connStr = ConfigurationManager.ConnectionStrings["MainConnStr"].ConnectionString;
                Bestlife.ERP.DataAccess.clsCon.connect(connStr);

                String Ssql = "SELECT [Pas_Word] FROM [Tbl_User] where Use_ID='" + uid + "'AND Pas_Word='" + password + "'";

                SqlDataReader rdR;
                rdR = clsCon.ReadTable(Ssql);

                if (rdR.Read())
                {
                    pass = "1";
                }
                else
                {
                    pass = "0";
                }

                rdR.Close();
            }
            catch (Exception)
            {
                // Console.WriteLine(exx)
            }
            finally 
            {
                clsCon.conn_new.Close();
            }
            return pass;

        }
        #endregion


        #region Update Password
        public static Boolean  UpdatePassword(String uname,String pass)
        {
            Boolean b = false;
            try
            {
                Bestlife.ERP.DataAccess.users user = new users();
                string uid = user.GetUserId(uname);

                String connStr = ConfigurationManager.ConnectionStrings["MainConnStr"].ConnectionString;
                Bestlife.ERP.DataAccess.clsCon.connect(connStr);

                SqlCommand act = new SqlCommand("UPDATE Tbl_User SET Pas_Word='" + pass + "' WHERE Use_ID='" + uid + "'", clsCon.conn_new);
                act.ExecuteNonQuery();

                SqlCommand disupdate = new SqlCommand("UPDATE Tbl_Distributor SET Pas_Word='" + pass + "' WHERE Dis_ID='" + uid + "'", clsCon.conn_new);
                disupdate.ExecuteNonQuery();
                b = true;
            }

            catch (Exception)
            {

               // Response.Redirect("404.aspx?Massage=" + err.Message.ToString());
            }

            finally
            {
                clsCon.conn_new.Close();
            }
            return b;
        }
        #endregion 
    }
}